#include "BitOps.h"
#include <avr/io.h>
#include "RS232.h"

void init_USART(void){
// Enable receiver and transmitter
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
UCSR0C = (0<<USBS0)|(1<<UCSZ01)|(1<<UCSZ00);

// Set baud rate
UBRR0H = (uint8_t)(BAUD_PRESCALE>>8);
UBRR0L = (uint8_t)BAUD_PRESCALE;

}

void put_on_USART( char *data ){
   while ((*data != '\0')){
		while (!(UCSR0A & (1 <<UDRE0))){
      		UDR0 = *data;
      		data++;
		}
   }
}

char USARTReadChar()
{
   //Wait untill a data is available

   while(!(UCSR0A & (1<<RXC0)))
   {
      //Do nothing
   }

   return UDR0;
}
